USE [JaxDug]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT [name] FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.InsertPresentation') AND TYPE IN (N'P', N'PC'))
BEGIN
	DROP PROC InsertPresentation
	PRINT 'DROP PROC InsertPresentation'
END
GO

-- ===============================================================
-- Author:		RbH
-- Create date: 2012.03.22
-- Description:	Inserts a new Presentation into the database
-- Ussage:		EXEC InsertPresentation
-- ===============================================================
CREATE PROCEDURE dbo.InsertPresentation
	@Title NVARCHAR(250),
	@Synopsis NVARCHAR(MAX),
	@StartDateTime DATETIME2,
	@EndDateTime DATETIME2,
	@Tags IntegerTable READONLY,
	@LocationID INT,
	@SpeakerID INT
AS
BEGIN
	SET NOCOUNT ON;
	
	DECLARE @PresentationID INT
	
    INSERT INTO dbo.Presentations ( EnteredDate, Title, Synopsis, SpeakerID, StartDateTime, EndDateTime , LocationID )
    VALUES  (GETDATE(), @Title, @Synopsis, @SpeakerID, @StartDateTime, @EndDateTime, @LocationID )
    
    SET @PresentationID = @@IDENTITY
    
    INSERT INTO dbo.PresentationTags ( PresentationID, TagID )
    SELECT @PresentationID, t.[Integer] FROM @Tags t
END
GO

PRINT 'CREATE PROC InsertPresentation'

GRANT EXEC ON InsertPresentation TO PublicDbUser
GO

PRINT 'GRANT EXEC ON InsertPresentation TO PublicDbUser'